package com.example.interview.example.mobileBilling;

import java.util.Date;

public class OrderedStrategyHolder<T> {
    private Date orderedMonth;
    private T computeStrategy;

    public T order(Date orderedMonth,T computeStrategy){
        T oldComputeStrategy = null;
        if(this.orderedMonth!=null && this.orderedMonth.before(orderedMonth)){
            oldComputeStrategy = this.computeStrategy;
        }
        this.orderedMonth = orderedMonth;
        this.computeStrategy = computeStrategy;

        return oldComputeStrategy;
    }

    public T getValidComputeStrategy(Date month){
        if(this.orderedMonth!=null && !month.before(orderedMonth)){
            return computeStrategy;
        }
        return null;
    }
}
